import {
    totalConfig,
    propName
} from 'server/config/templateConfig';
import utils from 'server/core/utils';

let mapConfig = totalConfig.map;
let buildingConfig = totalConfig.building;
let homeId = totalConfig.base.homeId;

//家信息
class HomeInfo {
    static getInstance() {
        if (!HomeInfo.instance) {
            HomeInfo.instance = new HomeInfo();
        }
        return HomeInfo.instance;
    }

    create(originHomeInfos) {
        originHomeInfos = originHomeInfos || {};
        let building = {};
        if (originHomeInfos.build) {
            if (mapConfig[homeId].building) {
                mapConfig[homeId].building.forEach(buildingId => {
                    if (!originHomeInfos.building || !originHomeInfos.building[buildingId]) {
                        building[buildingId] = {
                            hide: true
                        };
                        if (buildingConfig[buildingId].item) {
                            building[buildingId].item = Object.assign({}, buildingConfig[buildingId].item);
                        }
                    } else {
                        building[buildingId] = originHomeInfos.building[buildingId];
                 
                    }
                });
            }
        } else {
            mapConfig[homeId].building.forEach(buildingId => {
                building[buildingId] = {
                    item: Object.assign({}, buildingConfig[buildingId].item),
                    hide: true
                };
            });
        }

        return {
            building: building || {},
            homeBuilding: originHomeInfos.homeBuilding || {},
            build: originHomeInfos.build || false,
            goReady: originHomeInfos.goReady || false,
        };;
    }
}

export default HomeInfo.getInstance();